package com.freewater.cargotracker.domain.model.customer;

import org.apache.commons.lang3.Validate;

import java.io.Serializable;
import java.util.Objects;

public class Customer implements Serializable {

    private static final long serialVersionUID = 1L;
    private Long id;
    private CustomerNo customerNo;
    private String name;

    public Customer(CustomerNo customerNo, String name) {
        Validate.notNull(customerNo, "Customer ID is required");
        Validate.notNull(name, "Name is required");

        this.customerNo = customerNo;
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        Validate.notNull(id, "id is required");
        this.id = id;
    }

    public CustomerNo getCustomerID() {
        return customerNo;
    }

    public String getName() {
        return name;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || this.getClass() != obj.getClass()) {
            return false;
        }
        final Customer other = (Customer) obj;
        return this.sameValueAs(other);
    }

    @Override
    public int hashCode() {
        return Objects.hash(this.customerNo);
    }

    @Override
    public String toString() {
        return "Customer{" +
                "id=" + id +
                ", customerNo=" + customerNo +
                '}';
    }

    private boolean sameValueAs(Customer other) {
        return other != null
                && this.customerNo.sameValueAs(other.customerNo);
    }
}
